import {
  reqAlbumDetailData,
  reqAllNewdiscListData,
  reqNewdiscListData,
} from '@/api'

//  定义方法
const state = {
  newdiscList: [],
  allNewdiscList: [],
}

const actions = {
  // 1. 获取热门新碟数据的函数
  async getNewdiscListData({ commit }) {
    const result = await reqNewdiscListData()
    console.log('newdisclist', result)
    if (result.code === 200) {
      commit('SAVE_NEWDISC_LIST_DATA', result.albums)
    } else {
      console.log('失败')
    }
  },
  // 2. 获取全部新碟数据的函数
  async getAllNewdiscListData(
    { commit },
    { page: page, limit: limit, area: area }
  ) {
    const result = await reqAllNewdiscListData(page, limit, area)
    console.log('allnewdisc', result)
    if (result.code === 200) {
      commit('SAVE_ALLNEWDISC_DATA', result.albums)
    } else {
      console.log('失败')
    }
  },

  // 3. 获取专辑详情页的数据
  async getAlbumDetailData({commit},id) {
    const result =await reqAlbumDetailData(id)
    console.log('AlbumDetailData', result)
  },
}
const mutations = {
  // 存储热门新碟的数据
  SAVE_NEWDISC_LIST_DATA(state, newdiscList) {
    state.newdiscList = newdiscList
    // console.log('newdiscList', newdiscList)
  },
  // 存储全部新碟的数据
  SAVE_ALLNEWDISC_DATA(state, allNewdiscList) {
    state.allNewdiscList = allNewdiscList
    console.log('allNewdiscList', allNewdiscList)
  },
}
const getters = {}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters,
}
